#include <stdlib.h>
#include <clutter/clutter.h>

#define WINDOWS_WIDTH 400
#define WINDOWS_HEIGHT 400
#define UNUSED(x) (void)x

void on_action_clicked (ClutterClickAction *action,
               ClutterActor       *actor,
               gpointer            user_data)
{
    UNUSED(action);
    UNUSED(actor);
    UNUSED(user_data);
    printf("on_action_clicked \n");
}

static gboolean on_action_long_press (ClutterClickAction    *action,
               ClutterActor          *actor,
               ClutterLongPressState  state,
               gpointer              user_data)
{
    UNUSED(action);
    UNUSED(actor);
    UNUSED(state);
    UNUSED(user_data);
    
    switch (state)
    {
        case CLUTTER_LONG_PRESS_QUERY:
        printf("on_action_long_press CLUTTER_LONG_PRESS_QUERY\n");
        return TRUE;

        case CLUTTER_LONG_PRESS_ACTIVATE:
        printf("on_action_long_press CLUTTER_LONG_PRESS_ACTIVATE\n");
        return TRUE;

        case CLUTTER_LONG_PRESS_CANCEL:
        printf("on_action_long_press CLUTTER_LONG_PRESS_CANCEL\n");
        return FALSE;
    }

    return FALSE;
}

int main(int argc , char * argv[])
{
    if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    {
        return EXIT_FAILURE;
    }

    ClutterActor *stage = clutter_stage_new();
    clutter_stage_set_title (CLUTTER_STAGE (stage), "ClutterSignal");
    clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
    clutter_actor_set_size(stage, WINDOWS_WIDTH, WINDOWS_HEIGHT);
    clutter_actor_set_background_color (stage, CLUTTER_COLOR_Green);
    g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);


    /* add button */
    ClutterActor *button = clutter_actor_new ();
    clutter_actor_set_name (button, "button");
    clutter_actor_set_size (button, 100, 100);
    clutter_actor_set_margin_top (button, 40);
    clutter_actor_set_margin_left (button, 40);
    clutter_actor_set_margin_right (button, 10);
    clutter_actor_set_margin_bottom (button, 10);
    clutter_actor_set_background_color (button, CLUTTER_COLOR_DarkBlue);
    clutter_actor_add_child (stage, button);
    clutter_actor_set_reactive (button, TRUE);
    ClutterAction *action = clutter_click_action_new ();
    clutter_actor_add_action (button, action);
    g_signal_connect (action, "clicked", G_CALLBACK (on_action_clicked), NULL);
    g_signal_connect (action, "long-press", G_CALLBACK (on_action_long_press), NULL);

    clutter_actor_show (stage);
    clutter_main();
    return EXIT_SUCCESS;
}